<template>
    <div class="rx-form-item" :class="{'is-inline':form.inline}">
        <label class="label" v-if="label!==undefined" :style="{width:labelWidth||form.labelWidth}" :class="[{'is-require':isRequire},
                form.labelAlign?'form-label-'+ form.labelAlign:''
        ]">
            {{label}}
        </label>
        <div class="content" :style="{
            marginLeft:(form.labelAlign||labelAlign)=='top'?'0px':''||labelWidth||form.labelWidth,
            width:contentWidth||form.contentWidth
        }">
            <slot></slot>
        </div>
    </div>
</template>

<script>
export default {
    name: 'rx-form-item',
    inject: ['form'],
    props: {
        label: {
            type: String
        },
        labelWidth: {
            type: String
        },
        contentWidth: {
            type: String
        },
        isRequire: {
            type: Boolean,
            default: false
        },
        labelAlign:{
            type:String
        }
    }
}
</script>

<style lang="scss">
.rx-form-item {
  float: left;
  margin-bottom: 22px;

  &[right] {
    float: right;
  }
  &.is-inline{
      display: inline-block;
      float: none;
      vertical-align: middle;
  }
  .label {
    float: left;
    text-align: right;
    line-height: 40px;
    padding-right: 5px;
    // 是否必选
    &.is-require::before {
      content: "*";
      display: inline-block;
      width: 3px;
      height: 3px;
      color: #ff5b5b;
      margin-right: 3px;
    }
    // 对齐
    &.form-label-left{
        text-align: left
    }
    &.form-label-right{
        text-align: right
    }
    &.form-label-top{
        text-align: left;
        float:none;
        display: block;
    }
  }
}
</style>
